package ua.kpi_java_training.zabrodskyi.module3;

import java.util.Scanner;

/**
 * The class describes data acquisition from the console which are entered by
 * the user.
 * 
 * @author Maksym Zabrodskyi
 * @version 25-Jun-2013
 */
public class Input {

	/**
	 * Receives only a positive integer.
	 * 
	 * @param scanner
	 *            - the system scanner.
	 * @param message
	 *            - the text message for the user before data entry.
	 * 
	 * @return positive integer.
	 */
	public static int getPositiveNumber(Scanner scanner, String message) {
		int number = 0;
		number = getNumber(scanner, message);
		while (number <= 0) {
			Printer.printToConsole("Error: incorrect number.");
			number = getNumber(scanner, message);
		}
		return number;
	}

	/**
	 * Receives only an integer.
	 * 
	 * @param scanner
	 *            - the system scanner.
	 * @param message
	 *            - the text message for the user before data entry.
	 * 
	 * @return integer.
	 */
	public static int getNumber(Scanner scanner, String message) {
		int number = 0;
		System.out.println(message);
		while (!scanner.hasNextInt()) {
			Printer.printToConsole("Error: incorrect data.\n" + message);
			scanner.next();
		}
		number = scanner.nextInt();
		return number;
	}

}
